package com.shiro.test.mvc.controller;

import com.shiro.test.mvc.pojo.Menu;
import com.shiro.test.mvc.pojo.User;
import com.shiro.test.mvc.service.IMenuService;
import com.shiro.test.mvc.util.Constants;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2020/11/23 0023.
 */
@Controller
@RequestMapping("/menu.html")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @RequestMapping(params = "act=list")
    @ResponseBody
    public List<Menu> getTreeMenu(){
        return menuService.getTreeMenu();
    }

    @RequestMapping(params = "act=myTree")
    @ResponseBody
    public List<Menu> myTreeMenu(){
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getSession().getAttribute(Constants.SESSION_USER);
        return menuService.myTreeMenu(user.getId());
    }
}
